<template>
  <div>
    <div class="block">
      <span style="color:#b0b0b0 " class="demonstration">
        <i class="el-icon-date"></i>
        选择学期：</span
      >
      <el-cascader
        v-model="value"
        :options="options"
        :props="{ expandTrigger: 'hover' }"
        @change="handleChange"
      ></el-cascader>
    </div>

    <el-table
      v-loading="loading"
      :data="tableData"
      stripe
      style="padding:10px;width: 100%"
    >
      <el-table-column prop="xq" label="开课学期" width="180">
      </el-table-column>
      <el-table-column prop="ksxz" label="考试性质" width="180">
      </el-table-column>
      <el-table-column prop="bcxq" label="补重学期"> </el-table-column>
      <el-table-column prop="kcdm" label="课程代码" width="180">
      </el-table-column>
      <el-table-column prop="kcxh" label="课程序号" width="180">
      </el-table-column>
      <el-table-column prop="kcmc" label="课程名称" width="180">
      </el-table-column>
      <el-table-column prop="lb" label="课程类别" width="180">
      </el-table-column>

      <el-table-column prop="xf" label="学分" width="180"> </el-table-column>
      <el-table-column prop="kscj" label="成绩" width="180"> </el-table-column>
      <el-table-column label="考试性质" width="180">
        <template slot-scope="scope">
          <el-tag type="success">{{ scope.row.bz }}</el-tag>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import util from "@/libs/util.js";
import { get_score_school, get_xq } from "@/api/sys.user.js";
export default {
  data() {
    return {
      tableData: [],
      loading: false,
      options: []
    };
  },
  methods: {
    handleChange(value) {
      console.log(value);
      this.get_score_school1(value[1]);
    },
    // ...mapActions('d2admin/user', ['get_score_school']),
    get_score_school1(data) {
      console.log(data);
      this.loading = true;
      get_score_school({
        cookie: util.cookies.get("JSESSIONID"),
        semesterId: data
      }).then(res => {
        this.tableData = res.data.cj;
        this.loading = false;
      });
    },
    get_xq1() {
      get_xq({ cookie: util.cookies.get("JSESSIONID") }).then(res => {
        //json字符串转json对象
        //实例化json

        console.log(res.data.semesters);
        //提取选项

        // let options = res.data.semesters.map(item => {
        //   return {
        //     value: item.semesterId,
        //     label: item.semesterName
        //   };
        // });
        //对象转数组
        var options = [];
        let arr = Object.values(res.data.semesters);
        console.log(arr.length);
        for (let i = 0; i < arr.length; i++) {
          console.log(arr[i]);
          this.options.push({
            value: arr[i][0].schoolYear,
            label: arr[i][0].schoolYear,
            children: arr[i].map(item => {
              return {
                value: item.id,
                label: item.name == 1 ? "上学期" : "下学期"
              };
            })
          });
        }
        console.log(this.options);
      });
    }
  },

  created() {
    this.get_xq1();
    this.get_score_school1(223);
  }
};
</script>

<style>
.block {
  padding: 20px;
}
</style>
